home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / appoooh.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  8KB  |  307 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12. #define CHR1_OFST 0x00  /* palette page of char set #1 */
  13. #define CHR2_OFST 0x10  /* palette page of char set #2 */
  14.  
  15. unsigned char *appoooh_videoram2;
  16. unsigned char *appoooh_colorram2;
  17. unsigned char *appoooh_spriteram2;
  18. static unsigned char *dirtybuffer2;
  19. static struct osd_bitmap *tmpbitmap2;
  20.  
  21. static int scroll_x;
  22. static int flipscreen;
  23. static int priority;
  24.  
  25. /***************************************************************************
  26.  
  27.   Convert the color PROMs into a more useable format.
  28.  
  29.   Palette information of appoooh is not known.
  30.  
  31.   The palette decoder of Bank Panic was used for this driver.
  32.   Because these hardware is similar.
  33.  
  34. ***************************************************************************/
  35. void appoooh_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  36. {
  37.     int i;
  38.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  39.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  40.  
  41.     for (i = 0;i < Machine->drv->total_colors;i++)
  42.     {
  43.         int bit0,bit1,bit2;
  44.  
  45.         /* red component */
  46.         bit0 = (*color_prom >> 0) & 0x01;
  47.         bit1 = (*color_prom >> 1) & 0x01;
  48.         bit2 = (*color_prom >> 2) & 0x01;
  49.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  50.         /* green component */
  51.         bit0 = (*color_prom >> 3) & 0x01;
  52.         bit1 = (*color_prom >> 4) & 0x01;
  53.         bit2 = (*color_prom >> 5) & 0x01;
  54.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  55.         /* blue component */
  56.         bit0 = 0;
  57.         bit1 = (*color_prom >> 6) & 0x01;
  58.         bit2 = (*color_prom >> 7) & 0x01;
  59.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  60.  
  61.         color_prom++;
  62.     }
  63.  
  64.     /* color_prom now points to the beginning of the lookup table */
  65.  
  66.     /* charset #1 lookup table */
  67.     for (i = 0;i < TOTAL_COLORS(0);i++)
  68.         COLOR(0,i) = (*(color_prom++) & 0x0f)|CHR1_OFST;
  69.  
  70.     /* charset #2 lookup table */
  71.     for (i = 0;i < TOTAL_COLORS(1);i++)
  72.         COLOR(1,i) = (*(color_prom++) & 0x0f)|CHR2_OFST;
  73.  
  74.     /* TODO: the driver currently uses only 16 of the 32 color codes. */
  75.     /* 16-31 might be unused, but there might be a palette bank selector */
  76.     /* to use them somewhere in the game. */
  77. }
  78.  
  79.  
  80. /***************************************************************************
  81.  
  82.   Start the video hardware emulation.
  83.  
  84. ***************************************************************************/
  85. int appoooh_vh_start(void)
  86. {
  87.     if (generic_vh_start() != 0)
  88.         return 1;
  89.  
  90.     if ((dirtybuffer2 = malloc(videoram_size)) == 0)
  91.     {
  92.         generic_vh_stop();
  93.         return 1;
  94.     }
  95.     memset(dirtybuffer2,1,videoram_size);
  96.  
  97.     if ((tmpbitmap2 = osd_create_bitmap(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  98.     {
  99.         free(dirtybuffer2);
  100.         generic_vh_stop();
  101.         return 1;
  102.     }
  103.  
  104.     return 0;
  105. }
  106.  
  107. WRITE_HANDLER( appoooh_scroll_w )
  108. {
  109.     scroll_x = data;
  110. }
  111.  
  112. /***************************************************************************
  113.  
  114.   Stop the video hardware emulation.
  115.  
  116. ***************************************************************************/
  117. void appoooh_vh_stop(void)
  118. {
  119.     free(dirtybuffer2);
  120.     osd_free_bitmap(tmpbitmap2);
  121.     generic_vh_stop();
  122.  
  123. }
  124.  
  125. WRITE_HANDLER( appoooh_videoram2_w )
  126. {
  127.     if (appoooh_videoram2[offset] != data)
  128.     {
  129.         dirtybuffer2[offset] = 1;
  130.  
  131.         appoooh_videoram2[offset] = data;
  132.     }
  133. }
  134.  
  135.  
  136.  
  137. WRITE_HANDLER( appoooh_colorram2_w )
  138. {
  139.     if (appoooh_colorram2[offset] != data)
  140.     {
  141.         dirtybuffer2[offset] = 1;
  142.  
  143.         appoooh_colorram2[offset] = data;
  144.     }
  145. }
  146.  
  147. WRITE_HANDLER( appoooh_out_w )
  148. {
  149.     /* bit 0 controls NMI */
  150.     if (data & 0x01) interrupt_enable_w(0,1);
  151.     else interrupt_enable_w(0,0);
  152.  
  153.     /* bit 1 flip screen */
  154.     if ((data & 0x02) != flipscreen)
  155.     {
  156.         flipscreen = data & 0x02;
  157.         memset(dirtybuffer,1,videoram_size);
  158.         memset(dirtybuffer2,1,videoram_size);
  159.     }
  160.  
  161.     /* bits 2-3 unknown */
  162.  
  163.     /* bits 4-5 are playfield/sprite priority */
  164.     /* TODO: understand how this works, currently the only thing I do is draw */
  165.     /* the front layer behind sprites when priority == 0, and invert the sprite */
  166.     /* order when priority == 1 */
  167.     priority = (data & 0x30) >> 4;
  168.  
  169.     /* bit 6 ROM bank select */
  170.     {
  171.         unsigned char *RAM = memory_region(REGION_CPU1);
  172.  
  173.         cpu_setbank(1,&RAM[data&0x40 ? 0x10000 : 0x0a000]);
  174.     }
  175.  
  176.     /* bit 7 unknown (used) */
  177. }
  178.  
  179. static void appoooh_draw_sprites(struct osd_bitmap *dest_bmp,
  180.         const struct GfxElement *gfx,
  181.         unsigned char *sprite)
  182. {
  183.     int offs;
  184.  
  185.     for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  186.     {
  187.         int sy    = 256-16-sprite[offs+0];
  188.         int code  = (sprite[offs+1]>>2) + ((sprite[offs+2]>>5) & 0x07)*0x40;
  189.         int color = sprite[offs+2]&0x0f;    /* TODO: bit 4 toggles continuously, what is it? */
  190.         int sx    = sprite[offs+3];
  191.         int flipx = sprite[offs+1]&0x01;
  192.  
  193.         if(sx>=248) sx -= 256;
  194.  
  195.         if (flipscreen)
  196.         {
  197.             sx = 239- sx;
  198.             sy = 255- sy;
  199.             flipx = !flipx;
  200.         }
  201.         drawgfx( dest_bmp, gfx,
  202.                 code,
  203.                 color,
  204.                 flipx,flipscreen,
  205.                 sx, sy,
  206.                 &Machine->drv->visible_area,
  207.                 TRANSPARENCY_PEN , 0);
  208.      }
  209. }
  210.  
  211. /***************************************************************************
  212.  
  213.   Draw the game screen in the given osd_bitmap.
  214.   Do NOT call osd_update_display() from this function, it will be called by
  215.   the main emulation engine.
  216.  
  217. ***************************************************************************/
  218. void appoooh_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  219. {
  220.     int offs;
  221.     int scroll;
  222.  
  223.     /* for every character in the Video RAM, check if it has been modified */
  224.     /* since last time and update it accordingly. */
  225.     for (offs = videoram_size - 1;offs >= 0;offs--)
  226.     {
  227.         /* char set #1 */
  228.         if (dirtybuffer[offs])
  229.         {
  230.             int sx,sy,code,flipx;
  231.  
  232.             dirtybuffer[offs] = 0;
  233.  
  234.             sx = offs % 32;
  235.             sy = offs / 32;
  236.             code = videoram[offs] + 256 * ((colorram[offs]>>5) & 7);
  237.  
  238.             flipx = colorram[offs] & 0x10;
  239.             if (flipscreen)
  240.             {
  241.                 sx = 31 - sx;
  242.                 sy = 31 - sy;
  243.                 flipx = !flipx;
  244.             }
  245.             drawgfx(tmpbitmap,Machine->gfx[0],
  246.                     code,
  247.                     colorram[offs]&0x0f,
  248.                     flipx,flipscreen,
  249.                     8*sx,8*sy,
  250.                     0,TRANSPARENCY_NONE,0);
  251.         }
  252.         /* char set #2 */
  253.         if (dirtybuffer2[offs])
  254.         {
  255.             int sx,sy,code,flipx;
  256.  
  257.             dirtybuffer2[offs] = 0;
  258.  
  259.             sx = offs % 32;
  260.             sy = offs / 32;
  261.             code = appoooh_videoram2[offs] + 256 * ((appoooh_colorram2[offs]>>5) & 0x07);
  262.  
  263.             flipx = appoooh_colorram2[offs] & 0x10;
  264.             if (flipscreen)
  265.             {
  266.                 sx = 31 - sx;
  267.                 sy = 31 - sy;
  268.                 flipx = !flipx;
  269.             }
  270.             drawgfx(tmpbitmap2,Machine->gfx[1],
  271.                     code,
  272.                     appoooh_colorram2[offs]&0x0f,
  273.                     flipx,flipscreen,
  274.                     8*sx,8*sy,
  275.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  276.         }
  277.     }
  278.  
  279.     scroll = -scroll_x;
  280.     scroll = 0;
  281.  
  282.     /* copy the temporary bitmaps to the screen */
  283.     copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  284.  
  285.     if (priority == 0)    /* fg behind sprites */
  286.         copyscrollbitmap(bitmap,tmpbitmap,1,&scroll,0,0,&Machine->drv->visible_area,TRANSPARENCY_COLOR,CHR1_OFST);
  287.  
  288.     /* draw sprites */
  289.     if (priority == 1)
  290.     {
  291.         /* sprite set #1 */
  292.         appoooh_draw_sprites( bitmap, Machine->gfx[2],spriteram);
  293.         /* sprite set #2 */
  294.         appoooh_draw_sprites( bitmap, Machine->gfx[3],appoooh_spriteram2);
  295.     }
  296.     else
  297.     {
  298.         /* sprite set #2 */
  299.         appoooh_draw_sprites( bitmap, Machine->gfx[3],appoooh_spriteram2);
  300.         /* sprite set #1 */
  301.         appoooh_draw_sprites( bitmap, Machine->gfx[2],spriteram);
  302.     }
  303.  
  304.     if (priority != 0)    /* fg in front of sprites */
  305.         copyscrollbitmap(bitmap,tmpbitmap,1,&scroll,0,0,&Machine->drv->visible_area,TRANSPARENCY_COLOR,CHR1_OFST);
  306. }
  307.